package com.muse.aaa;

public class Intern {
    public static void main(String[] args) {
        String s1 = new StringBuilder("3").toString();
        String s2 = s1.intern();
        System.out.println("s1 == s2 is " + (s1 == s2));

        String s3 = new String("1") + new String("2");
        s3.intern();
        String s4 = "12";
        System.out.println("s3 == s4 is " + (s3 == s4));

        String str1 = new StringBuilder("计算机").append("软件").toString();
        String str2 = str1.intern();
        /**
         * System类中代码sun.misc.Version.init();
         * 进入后会看到String launcher_name = "java"; 表明已经被放入常量池中了。
         */
        String str3 = new StringBuilder("ja").append("va").toString();
        String str4 = str3.intern();
        System.out.println(str1==str2);
        System.out.println(str3==str4);
    }
}
